#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

BOOL Enumresnameproc(
    HMODULE hModule,
    LPCSTR lpType,
    LPSTR lpName,
    LONG_PTR lParam)
{
    std::cout << lpName << std::endl;
    return true;
}

int main(int argc, char **argv)
{
    // IMAGE_DATA_DIRECTORY
    std::string A = argc > 1 ? argv[1] : "SampleDll.dll";
    HMODULE hmod = LoadLibrary(A.c_str());
    if (!hmod)
    {
        cout << "hello world!" << endl;
        return -1;
    }

    HRSRC iohpp = FindResource(hmod, "iohpp", "iohpp");
    HGLOBAL hglobal = LoadResource(hmod, iohpp);
    auto *ptr = LockResource(hglobal);
    auto size = SizeofResource(hmod, iohpp);
    std::ofstream ofs("io.h", std::ios::binary | std::ios::out);
    ofs.write((char *)ptr, size);
    ofs.close();
    return 0;
}
